package com.zdp.springcloud.service;

import com.zdp.springcloud.domain.CommonResult;
import com.zdp.springcloud.domain.User;
import com.zdp.springcloud.service.impl.UserFallbackService;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 * @author sesshomaru
 * @date 2019/12/7 22:53
 * 1.默认 @FeignClient(value = "user-service")
 * 2.Feign中的服务降级使用起来非常方便，只需要为Feign客户端定义的接口添加一个服务降级处理的实现类即可，
 * 下面我们为UserService接口添加一个服务降级实现类。
 *   修改@FeignClient注解中的参数，设置fallback为UserFallbackService.class即可
 *   修改application.yml，开启Hystrix功能
 */
@FeignClient(value = "user-service",fallback = UserFallbackService.class)
public interface UserService {

    @PostMapping("/user/create")
    CommonResult create(@RequestBody User user);

    @GetMapping("/user/{id}")
    CommonResult<User> getUser(@PathVariable(value = "id") Long id);

    @GetMapping("/user/getByUsername")
    CommonResult<User> getByUsername(@RequestParam(value = "username") String username);

    @PostMapping("/user/update")
    CommonResult update(@RequestBody User user);

    @PostMapping("/user/delete/{id}")
    CommonResult delete(@PathVariable(value = "id") Long id);
}
